package com.yuqih.common.websocket;

import java.util.Map;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;

import javax.websocket.Session;

import org.bson.types.ObjectId;

public class SessionContainer {
	
	private final String sessionId;
	private final Session session;
	private final IWebSocketMessageHandler handler;
	private boolean state = true;		// 是否可运行
	private final IWebSocketIniter initer;
	private final BlockingQueue<Object> queue = new LinkedBlockingDeque<Object>();
	
	public SessionContainer(Session session,
			IWebSocketMessageHandler handler, IWebSocketIniter initer) {
		super();
		this.sessionId = new ObjectId().toHexString();
		this.session = session;
		this.handler = handler;
		this.initer = initer;
	}

	/**
	 * @return the session
	 */
	public Session getSession() {
		return session;
	}

	/**
	 * @return the queue
	 */
	public BlockingQueue<Object> getQueue() {
		return queue;
	}

	/**
	 * @return the userProperties
	 */
	public Map<String, Object> getUserProperties() {
		return session.getUserProperties();
	}

	/**
	 * @return the state
	 */
	public boolean isRunning() {
		return state;
	}

	/**
	 * @param state the state to set
	 */
	public void stop() {
		this.state = false;
	}

	/**
	 * @return the handler
	 */
	public IWebSocketMessageHandler getHandler() {
		return handler;
	}

	/**
	 * @return the initer
	 */
	public IWebSocketIniter getIniter() {
		return initer;
	}

	/**
	 * @return the sessionId
	 */
	public String getSessionId() {
		return sessionId;
	}

}
